<template lang="jade">
div.return-bar
  i.iconfont(@click="back()") &#xe668;
  风险评估
div.user-center.detail_top

  div.survey
    dl(v-for=" (index, item) in s_quest ")
      dt {{index+1}}.{{item.name}}


      dd.show(v-for=" (a, b) in item.list ")
        div(v-if=" item.single==true ")
          input(type="radio", v-model="item.checkedSpec", class="chk_2", ref="abc", name="checkA_{{index+1}}", id="checkbox_{{index+1}}_{{a+1}}", value="{{b.point}}")
          label(for="checkbox_{{index+1}}_{{a+1}}") {{b.tag}}.{{b.name}}
        div(v-else)
          input(type="checkbox",  v-model="item.checkedSpec", class="chk_2", ref="abc", name="checkA_{{index+1}}_{{a+1}}", id="checkbox_{{index+1}}_{{a+1}}", value="{{b.point}}", v-on:click="clickCheck")
          label(for="checkbox_{{index+1}}_{{a+1}}") {{b.tag}}.{{b.name}}


  div.fb_box
    input.m_btn.nowide(@click="submit_survey", type="button", value="提交")
  alert.custom_alert(:show.sync="showtoast", title="提示", button-text="确认", @on-hide="onAlterHide")
    {{toastmsg}}


  alert.custom_alert(:show.sync="toast_show", title="提示", button-text="确定") 你还没有填完选项
</template>

<style>
@import '~vux/dist/vux.css';
</style>

<script>
import '../../assets/sass/user/index.scss'
import {c_user_survey} from '../../config/api'
import {Dialog, Alert, Toast} from 'vux'
export default {

  data () {
    return {
    	info:{},
      items:[],
      page:1,
      busy:true,
      showtoast:false,
      toast_show:false,
      toastmsg:'',
      risk:'',
      risk_name:[],
      risk_point:[],
      selectZ:false,
      s_quest:[
        {
          name:"您目前的就业状况如何?",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"固定职业，收入稳定，变化不大", point:1},
            {tag:"B", name:"固定职业，以佣金收入为主", point:3},
            {tag:"C", name:"创业者、企业主或自由职业", point:5}
          ]
        },
        {
          name:"您希望通过投资理财，实现...?",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"避免财产损失。", point:1},
            {tag:"B", name:"资产稳健成长。", point:3},
            {tag:"C", name:"资产迅速成长。", point:5}
          ]
        },

        {
          name:"您对理财产品的看法是：",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"理财产品无风险，类似存款", point:1},
            {tag:"B", name:"理财产品应当保本，但收益不确定", point:3},
            {tag:"C", name:"理财产品本金可能产生损失,应当仔细选择", point:5}
          ]
        },

        {
          name:"您的投资经验可以被描述为：",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"有限，只有银行活期和定期存款。", point:1},
            {tag:"B", name:"一般，我拥有银行活期和定期存款外，还投资过其他形式的金融资产，有一定的投资经验，但需要进一步指导", point:3},
            {tag:"C", name:"丰富，我是一位积极和有经验的投资者，并倾向于自己作出投资决定", point:5}
          ]
        },

        {
          name:"您曾经选择的投资理财渠道?",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"存款", point:1},
            {tag:"B", name:"国债，银行稳健型理财产品，债券型基金，货币型基金", point:3},
            {tag:"C", name:"外汇，股票，期货、股票型基金", point:5}
          ]
        },

        {
          name:"您对投资产品风险的适应程度",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"保守型：在本金安全的情况下，投资收益必须达到我的最低要求，如同期定期存款收益", point:1},
            {tag:"B", name:"稳健型：在本金安全或者有较大保障的情况下，我愿意接受投资收益的波动，以获得大于同期存款的收益", point:3},
            {tag:"C", name:"激进型：为获得较高的投资回报，我愿意承担投资产品市值波动较大的风险", point:5}
          ]
        },

        {
          name:"您对P2P理财交易行为的了解程度",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"毫不了解，根本不想在此类产品上进行投资。", point:1},
            {tag:"B", name:"了解程度不高，只知道最近P2P行业越来越合规，很多人都在投。", point:3},
            {tag:"C", name:"比较关心，曾有投资过P2P平台或向专业人士咨询过此方面操作流程与存在的风险。", point:5}
          ]
        },

        {
          name:"您的投资资金占您全部个人资产的",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"75％以上", point:1},
            {tag:"B", name:"25－75％", point:3},
            {tag:"C", name:"0-25％", point:5}
          ]
        },

        {
          name:"一般情况下，您愿意选择( )投资期限的产品",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"半年以下", point:1},
            {tag:"B", name:"半年以上三年以内，且产品有一定资金流动性(如提供抵押、质押贷款服务)", point:3},
            {tag:"C", name:"三年以上", point:5}
          ]
        },

        {
          name:"您的年龄是?",
          checkedSpec:0,
          single:true,
          list:[
            {tag:"A", name:"大于60岁", point:1},
            {tag:"B", name:"40岁至60岁之间", point:3},
            {tag:"C", name:"40岁以下", point:5}
          ]
        },

        {
          name:"您是否做过以下投资?",
          checkedSpec:[],
          single:false,
          list:[
            {tag:"A", name:"余额宝", point:1.01},
            {tag:"B", name:"货币基金", point:1.02},
            {tag:"C", name:"信托", point:1.03},
            {tag:"D", name:"私募基金", point:1.04},
            {tag:"E", name:"公募基金", point:1.05},
            {tag:"F", name:"股票", point:1.06},
            {tag:"G", name:"银行理财", point:1.07},
            {tag:"H", name:"期货", point:1.08},
            {tag:"I", name:"以上均未投过", point:0}
          ]
        }
      ]
    }
  },
  components: {
    Dialog,
    Alert,
    Toast
  },
  methods: {
    back(){
      //this.$route.router.go('/auto-buy')
      window.history.back();
    },
    clickCheck(key){
      //console.log()
      var val = key.target.defaultValue;
      if(val==0 && key.target.type == 'checkbox'){
        this.s_quest[10].checkedSpec = ['0'];
        this.selectZ = true
      }

      if(val!=0 && key.target.type == 'checkbox'){
        //this.s_quest[10].checkedSpec = [];
        if(this.selectZ==true){
          this.s_quest[10].checkedSpec = [];
          this.selectZ = false;
          this.s_quest[10].checkedSpec.push(key.target.defaultValue)
        }
      }

    },
    chose(a, b, c){

        var add = false;

        for(var i in this.risk_name ){
          //console.log(this.risk_name[i])
          if(this.risk_name[i] == a ){
            add = false;
            break;
          }else{
            add = true;
          }
        }
        if(this.risk_name.length == 0)
          add = true;

        if(add == true){
          this.risk_name.push(a);
          this.risk_point.push(c);
        }else{
          this.risk_name.push(a);
        }

      console.log(this.risk_name);
      console.log(this.risk_point);
    },
    onAlterHide(){
      this.$route.router.go('/user');
    },
    submit_survey: function () {
      var apoint = 0, that = this;
      //var chk = document.getElementsByTagName('radio')
      //console.log(this.s_quest[10].checkedSpec)

      //return;

      for(var a=0;a<11;a++){
        console.log(this.s_quest[a].checkedSpec.length)
        if(this.s_quest[a].checkedSpec.length == undefined || this.s_quest[a].checkedSpec.length == 0){
          this.toast_show = true;
          return;
        }
        apoint = apoint + parseInt(this.s_quest[a].checkedSpec);
      }

      //判断第10条多选题
      var tenPoint = 0;
      for(var a in this.s_quest[10].checkedSpec){
        tenPoint = tenPoint + parseInt(this.s_quest[10].checkedSpec[a]);
      }


      if(tenPoint == 0)
        apoint = 0;
      else
        apoint = apoint + tenPoint;





      //console.log(this.s_quest[10].checkedSpec);
      console.log('apoint='+apoint);
      //return;

      //return;
      this.$http({url: c_user_survey+'&risk='+apoint, method: 'GET'}).then(function (rs) {
        //if(response.data.status == true )


        this.toastmsg = rs.data.msg;
        if(rs.data.status == true ){






          if(apoint == 0)
            this.toastmsg = '您没有做过非保本理财，不具备投资P2P资格';
          else
            this.toastmsg = this.toastmsg + ',确认回到会员中心!';
          /*setInterval(function(){
            that.$route.router.go('/user');
          },3000); */
        }
        this.showtoast = true;

        //this.busy = false;
      });
    }
  },
  route: {
    activate ( transition ) {
      /*if(sessionStorage.getItem("login")==null){
        this.$route.router.go('/login?from='+this.$route.path.substring(1))
        return false;
      }*/
    	transition.next();
    }
  }
}
</script>
